﻿using Adnc.Application.Shared;
using Adnc.WebApi.Shared;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using WYT.Usr.Application.Contracts.Dtos.Health;
using WYT.Usr.Application.Contracts.Services;

namespace WYT.Usr.WebApi.Controllers
{
    /// <summary>
    /// 健康自检
    /// </summary>
    [Route("usr/[Controller]")]
    [ApiController]
    public class HealthController : AdncControllerBase
    {
        private readonly IHealthAppService _healthAppService;
        private readonly IUserContext _userContext;

        public HealthController(IHealthAppService healthAppService,
            IUserContext userContext)
        {
            _healthAppService = healthAppService;
            _userContext = userContext;
        }

        /// <summary>
        /// 开始答题
        /// </summary>
        /// <param name="classify">类型</param>
        /// <returns></returns>
        [HttpGet("Exam")]
        public async Task<WYTActionResult<StartAnswerDto>> StartAnswer([FromQuery]int classify = 1)
        {
            return Success(await _healthAppService.StartAnswer(_userContext.Id, classify));
        }

        /// <summary>
        /// 提交答题
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("Submit")]
        public async Task<WYTActionResult<bool>> UserAnswer(UserAnswerParaDto input)
        {
            return Success(await _healthAppService.UserAnswer(input));
        }

        /// <summary>
        /// 获取报告
        /// </summary>
        /// <param name="id">检查记录ID</param>
        /// <returns></returns>
        [HttpGet("Report")]
        public async Task<WYTActionResult<HealthReportDto>> GetHealthUserExam([FromQuery]long id)
        {
            return Success(await _healthAppService.GetHealthUserExam(id));
        }
    }
}
